package sky.converters;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 01.05.13
 * Time: 18:32
 * To change this template use File | Settings | File Templates.
 */
public class StringToDateConverter implements Converter <String, Date> {

    @Override
    public Date convert(String dateString) {
        SimpleDateFormat format = new SimpleDateFormat();
        format.applyPattern("yyyy.MM.dd HH:mm:ss");
        try {
            return format.parse(dateString);
        } catch (ParseException e) {
            return new Date();
        }
    }
}
